/**
 * 
 */
package qualification2010;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.StringTokenizer;

/**
 * @author Coddy created on 2010-5-8
 * 
 */
public class SnapperChain
{
	static String currentInput = "A-large.in";
	// static String currentInput = "input.in";
	static String currentOutput = "A-large.out";

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
		try
		{
			BufferedReader bf = new BufferedReader(new FileReader(currentInput));
			BufferedWriter bw = new BufferedWriter(
					new FileWriter(currentOutput));
			int t = Integer.parseInt(bf.readLine());
			for (int testcase = 0; testcase < t; testcase++)
			{
				String line = bf.readLine();

				StringTokenizer tokenizer = new StringTokenizer(line);
				int k = 0, n = 0;
				if (tokenizer.hasMoreElements())
				{
					n = Integer.parseInt((String) tokenizer.nextElement());
					k = Integer.parseInt((String) tokenizer.nextElement());
				}

				k = (int) (k % (Math.pow(2, n)));
				StringBuffer sb = new StringBuffer();
				sb.append(toFullBinaryString(k));
				sb.append("1");
				sb.reverse();
				String string = sb.toString();
				// System.out.println(string);
				String state = null;
				int index = n;
				while (index > 0 && string.charAt(index) == '1')
					index--;
				if (index == 0)
				{
					state = "ON";
				} else
				{
					state = "OFF";
				}
				bw.write("Case #" + (testcase + 1) + ": " + state);
				bw.write("\n");
			}
			bw.flush();
		} catch (Exception e)
		{
			e.printStackTrace();// TODO: handle exception
		}

	}

	public static String toFullBinaryString(int num)
	{
		char[] chs = new char[Integer.SIZE];
		for (int i = 0; i < Integer.SIZE; i++)
		{
			chs[Integer.SIZE - 1 - i] = (char) (((num >> i) & 1) + '0');
		}
		return new String(chs);
	}
}
